Skip to content

fix(test-runner): warn users who invoke the test-runner with Jest - #7743

Merged
Max Schmitt (mxschmitt) merged 1 commit into
microsoft:masterfrom
mxschmitt:bugfix/warn-if-invoked-via-jest
Jul 22, 2021
Merged

fix(test-runner): warn users who invoke the test-runner with Jest#7743
Max Schmitt (mxschmitt) merged 1 commit into
microsoft:masterfrom
mxschmitt:bugfix/warn-if-invoked-via-jest

Conversation

@mxschmitt

@mxschmitt Max Schmitt (mxschmitt) commented Jul 20, 2021

Copy link
Copy Markdown
Contributor

Relates:

See here about the worker-index env var: https://jestjs.io/docs/environment-variables. Its probably the easiest way to detect if its Jest or not.

Before it lead to when using Jest on Playwright tests:

 FAIL  tests/foo.spec.js
  ● Test suite failed to run

    test() can only be called in a test file

      1 | const { test, expect } = require('@playwright/test');
      2 |
    > 3 | test('basic test', async ({ page }) => {
        | ^
      4 |   await page.goto('https://playwright.dev/');
      5 |   const name = await page.innerText('.navbar__title');
      6 |   expect(name).toBe('Playwright');

      at Object.<anonymous> (tests/foo.spec.js:3:1)

Not sure where to put, we can also put it on the top-level at the end of the file.

Comment thread src/test/testType.ts Outdated
Comment thread src/test/testType.ts Outdated
@mxschmitt
Max Schmitt (mxschmitt) force-pushed the bugfix/warn-if-invoked-via-jest branch 2 times, most recently from 2b5fa8a to 5ae366c Compare July 21, 2021 10:27
@JoelEinbinder

Copy link
Copy Markdown
Contributor

I agree with dmitry that it's impolite to throw immediately if we detect Jest. Let's just throw a better error message if we detect Jest when we currently throw test() can only be called in a test file.

Comment thread src/test/testType.ts Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants